package com.wang.learn.sharding.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wang.learn.sharding.entity.A31;
import com.wang.learn.sharding.mapper.A31Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class A31Controller {

    @Autowired
    private A31Mapper a31Mapper;

    @RequestMapping("/a31Add")
    public String a31Add(){
        A31 a31 = new A31();
        a31.setA3101("a3101");
        a31.setA3102("a3102");
        a31Mapper.insert(a31);
        return "success";
    }

    @RequestMapping("/a31List")
    public List<A31> a31List(){
        List<A31> a31s = a31Mapper.selectList(new QueryWrapper<>());
        return a31s;
    }

    @RequestMapping("/a31FindById")
    public List<A31> a31FindById(){
        QueryWrapper<A31> a31QueryWrapper = new QueryWrapper<>();
        List<Long> list = new ArrayList<>();
        list.add(1293818374667436033L);
        //list.add(1293812982403072002L);
        a31QueryWrapper.in(list.size()>0,"id",list);
        List<A31> a31s = a31Mapper.selectList(a31QueryWrapper);
        return a31s;
    }

    @RequestMapping("/a31FindByPage")
    public IPage<A31> a31FindByPage(){
        IPage<A31> userPage = new Page<A31>(0, 5);//参数一是当前页，参数二是每页个数
        IPage<A31> a31IPage = a31Mapper.selectPage(userPage, new QueryWrapper<A31>());
        return a31IPage;
    }

    @RequestMapping("/a31FindByIdOrder")
    public IPage<A31> a31FindByIdOrder(){
        IPage<A31> userPage = new Page<A31>(0, 3);//参数一是当前页，参数二是每页个数
        QueryWrapper<A31> a31QueryWrapper = new QueryWrapper<>();
        a31QueryWrapper.orderByDesc("id");
        IPage<A31> a31IPage = a31Mapper.selectPage(userPage, a31QueryWrapper);
        return a31IPage;
    }


}